package com.wysql.ascost.service.info;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wysql.ascost.common.base.BaseService;
import com.wysql.ascost.common.support.ConvertUtil;
import com.wysql.ascost.mapper.info.InfoImportresultDtlMapper;
import com.wysql.ascost.model.custom.Tablepar;
import com.wysql.ascost.model.info.InfoImportresultDtl;
import com.wysql.ascost.model.info.InfoImportresultDtlExample;
import com.wysql.ascost.util.SnowflakeIdWorker;
import com.wysql.ascost.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 导入操作台账（明细表） InfoImportresultDtlService
 *
 * @author wysqlauto_自动生成
 * @Title: InfoImportresultDtlService.java 
 * @Package com.wysql.ascost.service 
 * @email ${email}
 * @date 2025-02-25 13:36:14  
 **/
@Service
public class InfoImportresultDtlService implements BaseService<InfoImportresultDtl, InfoImportresultDtlExample> {
    @Autowired
    private InfoImportresultDtlMapper infoImportresultDtlMapper;


    /**
     * 分页查询
     *
     * @param
     * @param
     * @return
     */
    public PageInfo<InfoImportresultDtl> list(Tablepar tablepar, InfoImportresultDtl infoImportresultDtl) {
        InfoImportresultDtlExample testExample = new InfoImportresultDtlExample();
        //搜索
        if (StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
            testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
        } else {//大搜索
            testExample.createCriteria().andLikeQuery(infoImportresultDtl);
        }
        //表格排序
        if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
        }else{
        	testExample.setOrderByClause("createtime DESC");
        }
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<InfoImportresultDtl> list = infoImportresultDtlMapper.selectByExample(testExample);
        PageInfo<InfoImportresultDtl> pageInfo = new PageInfo<InfoImportresultDtl>(list);
        return pageInfo;
    }

    @Override
    public int deleteByPrimaryKey(String ids) {

        List<String> lista = ConvertUtil.toListStrArray(ids);
        InfoImportresultDtlExample example = new InfoImportresultDtlExample();
        example.createCriteria().andIdIn(lista);
        return infoImportresultDtlMapper.deleteByExample(example);


    }


    @Override
    public InfoImportresultDtl selectByPrimaryKey(String id) {

        return infoImportresultDtlMapper.selectByPrimaryKey(id);

    }


    @Override
    public int updateByPrimaryKeySelective(InfoImportresultDtl record) {
        return infoImportresultDtlMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(InfoImportresultDtl record) {

        //添加雪花主键id
        record.setId(SnowflakeIdWorker.getUUID());


        return infoImportresultDtlMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(InfoImportresultDtl record, InfoImportresultDtlExample example) {

        return infoImportresultDtlMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(InfoImportresultDtl record, InfoImportresultDtlExample example) {

        return infoImportresultDtlMapper.updateByExample(record, example);
    }

    @Override
    public List<InfoImportresultDtl> selectByExample(InfoImportresultDtlExample example) {

        return infoImportresultDtlMapper.selectByExample(example);
    }


    @Override
    public long countByExample(InfoImportresultDtlExample example) {

        return infoImportresultDtlMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(InfoImportresultDtlExample example) {

        return infoImportresultDtlMapper.deleteByExample(example);
    }

    /**
     * 分页查询
     *
     * @param
     * @param
     * @return
     */
    public PageInfo<InfoImportresultDtl> finddtlbyStep(Tablepar tablepar, InfoImportresultDtl infoImportresultDtl) {
        InfoImportresultDtlExample testExample = new InfoImportresultDtlExample();
        //搜索
        if (StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
            testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
        } else {//大搜索
            testExample.createCriteria().andLikeQuery(infoImportresultDtl);
        }
        //表格排序
        if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
            testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
        }else{
            testExample.setOrderByClause("createtime DESC");
        }
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<InfoImportresultDtl> list = infoImportresultDtlMapper.selectByExample(testExample);
        PageInfo<InfoImportresultDtl> pageInfo = new PageInfo<InfoImportresultDtl>(list);
        return pageInfo;
    }



}
